#include<stdlib.h>
#include<assert.h>

/* Internal configuration */
#include "Log.h"
#include "dbg.h"
#include "mod_fem_viewer.h"
#include "fv_config.h"
#include "fv_exception.h"
#include "fv_threads.h"

// GUI interface
#if defined(WIN32) && defined(VIEWER_WIN_GUI)
# include "win/Common.h"
# include "win/WinApp.h"
#elif defined(VIEWER_FGLT_GUI)
# include "glt/GlutWindow.h"
#elif defined(VIEWER_WX_GUI)
# include "wx/wxFemViewerApp.h"
#else
# error "Unknown GUI-type"
#endif
#include "AppImpl.hpp"

using namespace FemViewer;

#ifndef _USE_FV_LIB

FILE * out = stdout;
typedef Core<AppEngine> render_core;

int main(int argc, char **argv)

#else

typedef Core<AppEngine *> render_core;

femviewer_export
int init_mod_fem_viewer(int argc, char **argv, FILE *out)
#endif
{
	int result(-1);
	try{
		int logMode = (out == stdout) ? IO::LOGCONSOLE : IO::LOGFILE;
//#ifdef FV_DEBUG
		logMode |= IO::LOGCONSOLE;
//#endif
		IO::Log::Init(logMode,out,NULL);
		result = render_core::init(argc,argv,out);
	}
	catch(const fv_exception &ex)
	{
		std::cerr << ex << std::endl;
		//result = -1;
	}
	catch(...)
	{
		std::cerr << "Some errors while initializing render module!" << std::endl;
		//result = -1;
	}
	return result;
}

